<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
    <style>
        .layui-card-body{
            overflow: auto;
            height:180px;
        }
        .layui-card-body p{
            width:100%;
            display: inline-block;
        }
        p.info{
            cursor: pointer;
        }
        p.info:hover{
            color:#01AAED
        }
        button.right{
            float:right;
            margin:6px 0;
        }
    </style>
</head>

<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">审批</a>
            <a>
                <cite>审批</cite></a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
       onclick="window.history.go(-1)" title="后退">
        <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md6 workmanAssignment">
            <div class="layui-card">
                <div class="layui-card-header">施工产值<button class="layui-btn right workmanAssignment" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月施工总产值：&nbsp;<span></span>元</h3>
                </div>
            </div>
        </div>
<!--        <div class="layui-col-md6 workmanAccounts">-->
<!--            <div class="layui-card">-->
<!--                <div class="layui-card-header">工人分账</div>-->
<!--                <div class="layui-card-body">-->
<!--                    <h3 class="total" style="width:100%">当月分账总额：&nbsp;<span></span>元</h3>-->
<!--                </div>-->
<!--            </div>-->
<!--        </div>-->
        <div class="layui-col-md6 handymanAccount">
            <div class="layui-card">
                <div class="layui-card-header">杂工分账<button class="layui-btn right handymanAccount" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月杂工分账总额：&nbsp;<span></span>元</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 attendance">
            <div class="layui-card">
                <div class="layui-card-header">考勤<button class="layui-btn right attendance" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月出勤：&nbsp;<span></span>&nbsp;&nbsp;人工日</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 loan">
            <div class="layui-card">
                <div class="layui-card-header">现金借支<button class="layui-btn right loan" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月借支总额：&nbsp;<span></span>&nbsp;&nbsp;元</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 living">
            <div class="layui-card">
                <div class="layui-card-header">生活费<button class="layui-btn right living" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月生活费充值总额：&nbsp;<span class="recharge"></span>&nbsp;&nbsp;元；&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;退款总额：&nbsp;<span class="refund"></span>&nbsp;&nbsp;元</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 supplier">
            <div class="layui-card">
                <div class="layui-card-header">供应商<button class="layui-btn right supplier" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月采购总额：&nbsp;<span></span>&nbsp;&nbsp;元</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 consume">
            <div class="layui-card">
                <div class="layui-card-header">个人领料<button class="layui-btn right consume" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月领料总额：&nbsp;<span></span>&nbsp;&nbsp;元</h3>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 groupConsume">
            <div class="layui-card">
                <div class="layui-card-header">班组领料<button class="layui-btn right groupConsume" type="button" style="display: none">通过</button></div>
                <div class="layui-card-body">
                    <h3 class="total" style="width:100%">当月领料总额：&nbsp;<span></span>&nbsp;&nbsp;元</h3>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        // 异步数据加载
        var approvalId = getQueryString('approvalId');
        var projectId = getQueryString('projectId');
        var data = [];
        $.ajax({
            type:"post",
            url:url+'/approval/approval/approvalData',
            async:false,
            data:{
                approvalId:approvalId,
                token:getParam('token')
            },
            success:function(r){
                if(r.code == 100000){
                    data = r.data;
                    if (r.data.info.access == 0){
                        $('button.right').remove();
                    }
                }else{
                    tips('审批',r)
                }
            }
        });

        //施工产值
        var assignemntHtml = '';
        for (var i=0;i<data.workmanAssignment.area.length;i++){
            assignemntHtml += `<p class="info" data-id="${data.workmanAssignment.area[i].id}">${data.workmanAssignment.area[i].name}总产值：&nbsp;<span>${data.workmanAssignment.area[i].sum}</span>元</p>`
        }
        $('.workmanAssignment h3.total span').empty().html(data.workmanAssignment.total);
        $('.workmanAssignment h3.total').after(assignemntHtml);
        if (typeof data.info.result.workmanAssignment == "undefined" || data.info.result.workmanAssignment == 1){
            $('button.workmanAssignment').remove();
        }else{
            $('button.workmanAssignment').show();
        }
        $('.workmanAssignment').on('click','p.info',function(){
            var id = $(this).data('id');
            window.location.href = 'approvalDataAssignment.html?approvalId='+approvalId+'&projectId='+projectId+'&areaId='+id+'&result='+data.info.result.workmanAssignment;
        });
        $('button.workmanAssignment').on('click',function(){
            $.ajax({
                url:url+'/approval/workmanAssignment/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });

        //工人分账
        // var workmanAccountHtml = '';
        // for (var i=0;i<data.workmanAccount.group.length;i++){
        //     workmanAccountHtml += `<p class="info" data-id="${data.workmanAccount.group[i].id}">${data.workmanAccount.group[i].name}产值：&nbsp;<span>${data.workmanAccount.group[i].sum}</span>元</p>`
        // }
        // $('.workmanAccounts h3.total span').empty().html(data.workmanAccount.total);
        // $('.workmanAccounts h3.total').after(workmanAccountHtml);
        // $('.workmanAccounts').on('click','p.info',function(){
        //     var id = $(this).data('id')
        //     window.location.href = 'approvalDataAccount.html?approvalId='+approvalId+'&projectId='+projectId+'&groupId='+id;
        // });
        //杂工分账
        var handyAccountsHtml = '';
        for (var i=0;i<data.handymanAccount.area.length;i++){
            handyAccountsHtml += `<p class="info" data-id="${data.handymanAccount.area[i].id}">${data.handymanAccount.area[i].name}产值：&nbsp;<span>${data.handymanAccount.area[i].sum}</span>元</p>`
        }
        $('.handymanAccount h3.total span').empty().html(data.handymanAccount.total);
        $('.handymanAccount h3.total').after(handyAccountsHtml);
        if (typeof data.info.result.handymanAccounts == "undefined" || data.info.result.handymanAccounts == 1){
            $('button.handymanAccount').remove();
        }else{
            $('button.handymanAccount').show();
        }
        $('.handymanAccount').on('click','p.info',function(){
            var id = $(this).data('id')
            window.location.href = 'approvalDataHandymanAccount.html?approvalId='+approvalId+'&projectId='+projectId+'&areaId='+id+'&result='+data.info.result.handymanAccounts;
        });
        $('button.handymanAccount').on('click',function(){
            $.ajax({
                url:url+'/approval/handymanAccounts/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });
        //考勤
        var attendanceHtml = '';
        for (var i=0;i<data.attendance.profession.length;i++){
            attendanceHtml += `<p class="info" data-id="${data.attendance.profession[i].id}">${data.attendance.profession[i].name}当月出勤：&nbsp;<span>${data.attendance.profession[i].sum}</span>&nbsp;人工日</p>`
        }
        $('.attendance h3.total').after(attendanceHtml)
        $('.attendance h3.total span').empty().html(data.attendance.total);
        if (typeof data.info.result.attendance == "undefined" || data.info.result.attendance == 1){
            $('button.attendance').remove();
        }else{
            $('button.attendance').show();
        }
        $('.attendance').on('click','p.info',function(){
            var id = $(this).data('id')
            window.location.href = 'approvalDataAttendance.html?approvalId='+approvalId+'&projectId='+projectId+'&professionId='+id+'&result='+data.info.result.attendance;
        });
        $('button.attendance').on('click',function(){
            $.ajax({
                url:url+'/approval/attendance/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });
        //现金借支
        var loanHtml = '';
        for (var i=0;i<data.loan.profession.length;i++){
            loanHtml += `<p class="info" data-id="${data.loan.profession[i].id}">${data.loan.profession[i].name}借支：&nbsp;<span>${data.loan.profession[i].sum}</span>元</p>`
        }
        $('.loan h3.total').after(loanHtml)
        $('.loan h3.total span').empty().html(data.loan.total);
        if (typeof data.info.result.loan == "undefined" || data.info.result.loan == 1){
            $('button.loan').remove();
        }else{
            $('button.loan').show();
        }
        $('.loan').on('click','p.info',function(){
            var id = $(this).data('id')
            window.location.href = 'approvalDataLoan.html?approvalId='+approvalId+'&projectId='+projectId+'&professionId='+id+'&result='+data.info.result.loan;
        });
        $('button.loan').on('click',function(){
            $.ajax({
                url:url+'/approval/loan/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });
        //生活费
        var livingHtml = '';
        for (var i=0;i<data.living.profession.length;i++){
            livingHtml += `<p class="info" data-id="${data.living.profession[i].id}">${data.living.profession[i].name}生活费充值：&nbsp;<span>${data.living.profession[i].sum_recharge}</span>元；退款：&nbsp;<span>${data.living.profession[i].sum_refund}</span>元</p>`
        }
        $('.living h3.total').after(livingHtml)
        $('.living h3.total span.recharge').empty().html(data.living.total_recharge);
        $('.living h3.total span.refund').empty().html(data.living.total_refund);
        if (typeof data.info.result.living == "undefined" || data.info.result.living == 1){
            $('button.living').remove();
        }else{
            $('button.living').show();
        }
        $('.living').on('click','p.info',function(){
            var id = $(this).data('id')
            window.location.href = 'approvalDataLiving.html?approvalId='+approvalId+'&projectId='+projectId+'&professionId='+id+'&result='+data.info.result.living;
        });
        $('button.living').on('click',function(){
            $.ajax({
                url:url+'/approval/living/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });
        //仓库账目
        var supplierHtml = '';
        for (var i=0;i<data.supplier.supplier.length;i++){
            supplierHtml += `<p class="info" data-id="${data.supplier.supplier[i].id}">${data.supplier.supplier[i].name}：&nbsp;<span>${data.supplier.supplier[i].sum}</span>元</p>`
        }
        $('.supplier h3.total span').empty().html(data.supplier.total);
        $('.supplier h3.total').after(supplierHtml)
        if (typeof data.info.result.supplier == "undefined" || data.info.result.supplier == 1){
            $('button.supplier').remove();
        }else{
            $('button.supplier').show();
        }
        $('.supplier').on('click','p.info',function(){
            var id = $(this).data('id')
            window.location.href = 'approvalDataSupplier.html?approvalId='+approvalId+'&projectId='+projectId+'&supplierId='+id+'&result='+data.info.result.supplier;
        });
        $('button.supplier').on('click',function(){
            $.ajax({
                url:url+'/approval/supplier/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        });
        //个人领料
        var consumeHtml = '';
        if (typeof data.consume.employee != "undefined"){
            for (var i=0;i<data.consume.employee.length;i++){
                consumeHtml += `<p class="info" data-id="${data.consume.employee[i].id}">${data.consume.employee[i].name}领料总额：&nbsp;<span>${data.consume.employee[i].sum}</span>元</p>`
            }
            $('.consume h3.total').after(consumeHtml);
        }
        $('.consume h3.total span').empty().html(data.consume.total);
        if (typeof data.info.result.consume == "undefined" || data.info.result.consume == 1){
            $('button.consume').remove();
        }else{
            $('button.consume').show();
        }
        $('.consume').on('click','p.info',function(){
            var id = $(this).data('id');
            window.location.href = 'approvalDataConsume.html?approvalId='+approvalId+'&projectId='+projectId+'&employeeId='+id+'&result='+data.info.result.consume;
        });
        $('button.consume').on('click',function(){
            $.ajax({
                url:url+'/approval/consume/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    type:4,
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        })
        //班组领料
        var groupConsumeHtml = '';
        for (var i=0;i<data.groupConsume.group.length;i++){
            groupConsumeHtml += `<p class="info" data-id="${data.groupConsume.group[i].id}">${data.groupConsume.group[i].name}领料总额：&nbsp;<span>${data.groupConsume.group[i].sum}</span>元</p>`
        }
        $('.groupConsume h3.total span').empty().html(data.groupConsume.total);
        $('.groupConsume h3.total').after(groupConsumeHtml);
        if (typeof data.info.result.groupConsume == "undefined" || data.info.result.groupConsume == 1){
            $('button.groupConsume').remove();
        }else{
            $('button.groupConsume').show();
        }
        $('.groupConsume').on('click','p.info',function(){
            var id = $(this).data('id');
            window.location.href = 'approvalDataGroupConsume.html?approvalId='+approvalId+'&projectId='+projectId+'&groupId='+id+'&result='+data.info.result.groupConsume;
        });
        $('button.groupConsume').on('click',function(){
            $.ajax({
                url:url+'/approval/groupConsume/consent',
                type:"post",
                data:{
                    approvalId: approvalId,
                    processId:Number(data.info.processId),
                    type:7,
                    token: getToken()
                },
                success:function(r){
                    if(r.code==100000){
                        window.location.reload();
                    }else{
                        tips('审批',r);
                    }
                }
            })
        })
    });

</script>
</html>